package com.htime.util;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by HTime on 2017/3/5.
 */
public class DateUtil {

    public static final long ONE_DAY_MSEC= 24 * 3600 * 1000;
    public static final long ONE_MIN_MSEC=60*1000;
    public static final long ONE_MIN_SEC=60;
    public static final String SIMPLE_DATE_FORMAT= "yyyy-MM-dd";
    public static final String SIMPLE_DATETIME_FORMAT= "yyyy-MM-dd HH:mm:ss";
    public static final String ALIPAY_DATETIME_FORMAT= "yyyy/MM/dd HH:mm:ss";
    public static final String WXPAYPAY_DATETIME_FORMAT= "yyyyMMddHHmmss";

    public static int calculateDays(Date preDate, Date curDate) {

        //pre time
        Calendar preCal = Calendar.getInstance();
        preCal.setTime(preDate);
        preCal.set(Calendar.HOUR_OF_DAY, 0);
        preCal.set(Calendar.MINUTE, 0);
        preCal.set(Calendar.SECOND, 0);
        preCal.set(Calendar.MILLISECOND, 0);

        //cur time
        Calendar curCal = Calendar.getInstance();
        curCal.setTime(curDate);
        curCal.set(Calendar.HOUR_OF_DAY, 0);
        curCal.set(Calendar.MINUTE, 0);
        curCal.set(Calendar.SECOND, 0);
        curCal.set(Calendar.MILLISECOND, 0);

        long dayDiff =(curCal.getTimeInMillis()-preCal.getTimeInMillis())/(1000*60*60*24);

        return (int)dayDiff ;
    }

}
